home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Code / Chapter Code.exe / Chapter09 / BackForthPanel.java < prev    next >
Text File  |  2000-08-27  |  1KB  |  60 lines

  1.  
  2. package applets;
  3.  
  4. import shout3d.*;
  5. import shout3d.core.*;
  6. import shout3d.math.*;
  7.  
  8.  
  9. public class BackForthPanel extends Shout3DPanel implements RenderObserver{
  10.    
  11.    
  12.    Transform t;
  13.    float xPos;
  14.    float speed = 1.0f; //in meters per second
  15.    float limit = 3.0f;
  16.  
  17.  
  18.  
  19.    public BackForthPanel (Shout3DApplet applet){
  20.       super(applet);
  21.    }
  22.    
  23.    
  24.    public void customInitialize() {
  25.       getRenderer().addRenderObserver(this, null);
  26.  
  27.       t = (Transform) getNodeByName("trans");
  28.       xPos = t.translation.getValue()[0];      
  29.    }
  30.  
  31.  
  32.    protected void finalize()  { 
  33.       getRenderer().removeRenderObserver(this);
  34.    }
  35.  
  36.  
  37.  
  38.    public void onPreRender (Renderer r, Object o) {
  39.       
  40.       float xDelta = speed/getFramesPerSecond();
  41.       xPos = xPos + xDelta;
  42.  
  43.       if (xPos >= limit || xPos <= -limit)  {
  44.       
  45.          speed = -speed;
  46.       }
  47.       
  48.       t.translation.set1Value(0, xPos);
  49.    
  50.    }
  51.    
  52.  
  53.    public void onPostRender (Renderer r, Object o) {
  54.    
  55.    
  56.    }
  57.  
  58.    
  59.  
  60. } //end of class